package net.yambal.RTM.Method
{
	import flash.events.EventDispatcher;
	
	import net.yambal.RTM.Event.RestErrorEvent;
	import net.yambal.RTM.Event.RestEvent;
	import net.yambal.RTM.Event.TimezoneEvent;
	import net.yambal.RTM.Items.RTMTransaction;
	import net.yambal.RTM.RestWrapper.RestManager;
	import net.yambal.RTM.RestWrapper.RestService;
	import net.yambal.RTM.Utilty.Parser;
	
	[Event(name="get_list", type="net.yambal.RTM.Event.TimezoneEvent")]
	public class Timezones extends EventDispatcher
	{
		public function Timezones()
		{
		}
		
		/**
		 * タイムゾーンのリストを得る
		 **/
		public function getList(api_key:String, shared_secret:String):void{
			var p:Object = new Object();
			p.api_key = api_key;
			
			var RM:RestManager = new RestManager();
			RM.doMethod(RestService.METHOD_TIMEZONE_GET_LIST, p, this.onGetList, this.onFaultGetList, false, shared_secret);
		}
		
		private function onFaultGetList(code:Number, massage:String, ro:Object):void{
			trace(code);
			trace(massage);
		}
		
		private function onGetList(result_xml:XML, ro:Object, t:RTMTransaction):void{
			var tz:Array = Parser.TimeZoneXMLListToTimezone(result_xml.descendants("timezone"));
			this.dispatchEvent(new TimezoneEvent(TimezoneEvent.GET_LIST, tz));
		}

	}
}